using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Module.CMS.Library.Zones;
using NCS.Library.Utilities;
using NCS.Library;
using NCS.Module.CMS.Library.Definitions;

namespace NCS.Module.CMS.Web.SubPortal
{
    public partial class LeftMenu : CMSWebControl
    {
        public DataTable dt = null;
        public DataTable dt1 = null;
        public DataTable dt2 = null;

        protected void Page_Load(object sender, EventArgs e)
        {

            int parentID = 0;
            //this.dt = ZoneController.GetZones(parentID, ConvertUtility.ToInt32(Portal[Constants.CMS_Portal + AppEnv.GetLanguage()]).ToString());
            this.dt = ZoneController.GetZonesVisbleInNavbar(ConvertUtility.ToInt32(AppEnv.PortalId()));
            //foreach (DataRow dr in this.dt.Rows)
            //{
            //    if (NCS.Library.Utilities.ConvertUtility.ToInt32(dr["Zone_ParentID"]) != 0)
            //    {

            //    }
            //}
            if (this.dt.Rows.Count > 0)
            {
                DataListintro.DataSource = dt;
                DataListintro.DataBind();
            }
           

        }
        protected void OnItemDatabounds(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        {

            Label m_lableID = (Label)e.Item.FindControl("txtID");
            Int32 m_ID = Convert.ToInt32(m_lableID.Text.ToString());
            try
            {
                string _CatID = Request.QueryString["catid"].ToString();
                int _Parentzon = GetZoneParrentID(ConvertUtility.ToInt32(_CatID.ToString()));

                if ((Request.QueryString["catid"].ToString() == m_lableID.Text) || (_Parentzon == m_ID))
                {
                    this.dt1 = ZoneController.GetZones(ConvertUtility.ToInt32(m_ID), AppEnv.PortalId());
                    Literal SqlDataS = (Literal)e.Item.FindControl("ltrRepeatet");
                    SqlDataS.Text = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id=\"nav2\">";
                    SqlDataS.Text += "<tr><td width=\"1\"></td><td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> ";

                    for (int i = 0; i < dt1.Rows.Count; i++)
                    {
                        this.dt2 = ZoneController.GetZones(ConvertUtility.ToInt32(dt1.Rows[i]["Zone_ID"]), AppEnv.PortalId());
                        if (this.dt2.Rows.Count > 0)
                        {
                            SqlDataS.Text += "<tr><td class=\"nav2\">";
                            SqlDataS.Text += "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" onmouseover=\"MM_showHideLayers('nav5','','show')\" onmouseout=\"MM_showHideLayers('nav5','','hide')\">";
                            SqlDataS.Text += "<tr><td width=\"1\"></td><td width=\"13\" height=\"26\"><img src=\"/images/icon_nav.gif\" width=\"9\" height=\"5\" /></td>";
                            SqlDataS.Text += "<td class=\"nav2\">";
                            SqlDataS.Text += "<a class=\"nav2\" href=\"" + BuildUrlByZoneSubPortal(ConvertUtility.ToInt32(Convert.ToString(dt1.Rows[i]["Zone_ID"])), ConvertUtility.ToInt32(Convert.ToString(dt1.Rows[i]["Portal_TabControlID"]))) + "\" >" + dt1.Rows[i]["Zone_Name"] + " </a><div class=\"none\" id=\"nav5\">";
                            SqlDataS.Text += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td valign=\"top\" bgcolor=\"#a5b0bc\">";
                            SqlDataS.Text += "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">";
                            for (int j = 0; j < dt2.Rows.Count; j++)
                            {
                                SqlDataS.Text += "<tr><td bgcolor=\"#FFFFFF\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                                SqlDataS.Text += "<tr><td height=\"26\" bgcolor=\"#f3f3f3\" class=\"nav3\"><a class=\"nav3\" href=\"" + BuildUrlByZoneSubPortal(ConvertUtility.ToInt32(Convert.ToString(dt2.Rows[j]["Zone_ID"])), ConvertUtility.ToInt32(Convert.ToString(dt2.Rows[j]["Portal_TabControlID"]))) + "\" >" + dt2.Rows[j]["Zone_Name"] + " </a></td></tr>";
                                SqlDataS.Text += "<tr><td bgcolor=\"#a5b0bc\"><img src=\"/images/blank.gif\" width=\"1\" height=\"1\" /></td></tr>";
                                SqlDataS.Text += "</table></td></tr>";
                            }
                            SqlDataS.Text += "</table></td></tr></table>";

                            SqlDataS.Text += "</div></td></tr></table></td></tr>";

                        }
                        else
                        {
                            SqlDataS.Text += "<tr><td class=\"nav2\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
                            SqlDataS.Text += "<td width=\"1\"></td><td width=\"13\" height=\"26\"><img src=\"/images/icon_nav.gif\" width=\"9\" height=\"5\" /></td>";
                            SqlDataS.Text += "<td class=\"nav2\"><a class=\"nav2\" href=\"" + BuildUrlByZoneSubPortal(ConvertUtility.ToInt32(Convert.ToString(dt1.Rows[i]["Zone_ID"])), ConvertUtility.ToInt32(Convert.ToString(dt1.Rows[i]["Portal_TabControlID"]))) + "\" >" + dt1.Rows[i]["Zone_Name"] + " </a></td></tr></table></td></tr>";
                            SqlDataS.Text += "<tr><td background=\"/images/line_nav.gif\"><img src=\"/images/blank.gif\" width=\"1\" height=\"1\" /></td></tr>";

                        }
                        
                    }
                    SqlDataS.Text += "</table></td><td width=\"2\"></td></tr></table>";
                }
            }
            catch
            {
                return;
            }


        }
        private int GetZoneParrentID(int ID)
        {
            ZoneInfo info = ZoneController.GetZone(ID);
            if (info.Zone_ParentID != 0)
            {
                int _return = 0;
                _return = GetZoneParrentID(info.Zone_ParentID);
                return _return;
            }
            return info.Zone_ID;
        }
    }
}